<?


class CTRLpage extends CONTROL {

#	In parent class:
#	function asset()
#	function ajax()

	function __construct( $vars ) {
		global $Object, $Page;
		
		$this->_addvars( $vars );
		
		// Create object
		$Page = $Object	= ( $this->action == "new" )?
			new PAGE( null, "..." ) : new PAGE( $this->vars->id );
		
		$this->id	= $Object->get( 'ID' );
	}

	
#	Edit Page.
	function filter_edit() {
		global $DB, $Engine, $Object;
		
		if( $Object->mods->ids() && $mods = $Object->get( 'mods' ))
			foreach( $mods as $ckey => $column )
				if ( count($column ))
					$modcluster[ $ckey ] = $Object->mods->filter_core( $ckey );


		foreach( json_decode( engine_get( "control.columns" )) as $clm)
			$droppack[] = "new Dropbox({ descr:'$clm', type:'module', blank:'add module', ctype:'$clm', floats:[{$modcluster[ $clm ]}], page:'{$Object->name}', parentid:{$this->id} })";
			

		$red = $Object->get( "redirect" );
		if( $pages = $DB->filter_key( "page", "ID != {$this->id} && active=1 && !private order by parent, hierarchy limit 18", "ID as `key`, name as value" ))
			array_unshift( $pages, array( "key"=> 0, "value"=> " _ " ));
		
		return "
		ref.seed([
			
			new Element( 'h1' ).update( 'Beheer pagina ' ).insert( new Element( 'a', { href:'http://". engine_get('control.public') ."/{$Object->get('name')}', target:'_blank' }).update( '{$Object->get('title')}' )),
			new Textfield({ descr:'name page', type:'page', parentid:$this->id, textid:{$Object->get('nameid')}, values:". json_encode( $Engine->text->filter( $Object->get( 'nameid' ))) ." }),
			new Element( 'h2' ).update( 'Structuur' ),
			". implode(', ', $droppack) .",
			new Options({ descr:'Opties', active:true, floats: [
				new Shift({ type:'page', descr:'Show in menu', value:" . (( $Object->get( 'active' ) == 1 )?1:0 ) . ", field:'active', options:[2,1], objid:{$Object->id} }),
				new Ajxfield({ type:'page', descr:'url-naam', objid:{$this->id}, field:'name', value:'{$Object->get( 'name' )}' }),
				new Select({ type: 'page', descr:'redirect', objid: {$this->id}, field:'meta.redirect', key: '$red', opts: " . json_encode( $pages ) . " })
			]}),
			new Options({ descr:'Connect object', floats: [
				new Select({ type: 'page', descr:'object type', objid: {$this->id}, field:'meta.objtype', key: '{$Object->get( 'objtype' )}', opts: engine.type_to_opts() }),
				new Ajxfield({ type:'page', descr:'object id', objid:{$this->id}, field:'meta.objid', value:'{$Object->get( 'objid' )}' })
			]}),
			new Options({ descr:'Meta', floats: [
				new Htmlfield({ descr:'meta text (SEO)', type:'page', parentid:$this->id, textid:{$Object->get('textid')}, values:". json_encode(  $Engine->text->filter( $Object->get( 'textid' ), 'long' )) ." })
			]})
		]);";

	}


#	Change hierarchy.
	function filter_sortable() {
		global $DB;
		
		foreach( $this->vars->floats as $rank => $page )
			$DB->query( "update pages set parent={$this->vars->id}, hierarchy=$rank where ID=". $page->id );
		
		return $this->comment( "Page hierarchy updated." );
	}
	
}


?>
